package com.day1909d_xiangmu.weinfo.ui.fragment;

import android.content.Intent;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import com.day1909d_xiangmu.weinfo.base.BaseFragment;
import com.day1909d_xiangmu.weinfo.bean.DailyNewsBean;
import com.day1909d_xiangmu.weinfo.presenter.DailyNewsPresenter;
import com.day1909d_xiangmu.weinfo.presenter.DiscoveryPresenter;
import com.day1909d_xiangmu.weinfo.ui.activity.CalendarActivity;
import com.day1909d_xiangmu.weinfo.ui.activity.LoginActivity;
import com.day1909d_xiangmu.weinfo.ui.adapter.RlvDailyNewsAdapter;
import com.day1909d_xiangmu.weinfo.view.DiscoveryView;


import com.example.my1909_xaingmu.R;
import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class DiscoveryFragment extends BaseFragment<DiscoveryPresenter> implements DiscoveryView {

    @BindView(R.id.rlv)
    RecyclerView mRlv;
    @BindView(R.id.fab)
    FloatingActionButton mFab;
    private RlvDailyNewsAdapter mAdapter;

    /**
     *
     * @return
     */
    public static DailyNewsFragment getInstance(){
        DailyNewsFragment fragment = new DailyNewsFragment();
        return fragment;
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        mPresenter.getLastesNews();
    }

    @Override
    protected DailyNewsPresenter initPresenter() {
        return new DailyNewsPresenter();
    }

    @Override
    protected void initView(View view) {
        mRlv.setLayoutManager(new LinearLayoutManager(getContext()));
        ArrayList<DailyNewsBean.TopStoriesBean> bannerList = new ArrayList<>();
        ArrayList<DailyNewsBean.StoriesBean> newsList = new ArrayList<>();
        mAdapter = new RlvDailyNewsAdapter(getContext(), bannerList, newsList);
        mRlv.setAdapter(mAdapter);
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_daily_news;
    }


    @OnClick(R.id.fab)
    public void click(View v){
        switch (v.getId()) {
            case R.id.fab:
                startActivity(new Intent(getContext(), CalendarActivity.class));
                break;
        }
    }

    @Override
    public void setData(DailyNewsBean dailyNewsBean) {
        mAdapter.setData(dailyNewsBean);
    }
}
